<template>
  <a-modal v-model="visible" title="请选择税局" @ok="handleOk" :confirm-loading="confirmLoading" @cancel="$emit('update:visible', false)">
    <a-form :form="form" :selfUpdate="true" :label-col="{ span: 5 }" :wrapper-col="{ span: 18 }">
      <a-form-item label="企业/税局">
        <a-input v-show="false" v-decorator="['resourceUserId', { rules: [{ required: true, message: '企业/税局不能为空' }] }]" />
        <authorityCascader :visible="visible" @upDate="upDate" />
        <div class="desc">请选择本次导入报送人员的所属税局</div>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script>
import moment from "moment";
import { getCompanyAuthoritiesListAll } from "./api";
import authorityCascader from "../../component/authorityCascader";
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  components: {
    authorityCascader
  },
  watch: {
    visible(v) {
      if (!v) {
        this.form.resetFields();
      }
    }
  },
  created() {
    this.onGetCompanyAuthoritiesListAll();
  },
  data() {
    return {
      confirmLoading: false,
      form: this.$form.createForm(this, {}),
      companyArr: []
    };
  },
  methods: {
    moment,
    upDate(e) {
      setTimeout(() => {
        this.form.setFieldsValue({
          resourceUserId: e[1]
        });
      });
    },
    async onGetCompanyAuthoritiesListAll(v) {
      try {
        const { data } = await getCompanyAuthoritiesListAll(v);
        this.companyArr = data;
      } catch (err) {
        console.log("error log --> ", err);
      }
    },
    handleOk() {
      this.form.validateFields((err, values) => {
        if (!err) {
          this.$router.push({ name: "taxCalculatePeopleImportAdd", query: { id: values.resourceUserId } });
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.desc {
  font-size: 12px;
  font-family: SourceHanSansCN-Regular, SourceHanSansCN;
  font-weight: 400;
  color: #a6a8b4;
}
</style>
